/* hooks */
import { useStorage, StorageModuleEnum, StorageSetType } from '@hooks/use-storage';
// @ts-ignore
import { getUserId } from '@src/util/storage.ts';
import _ from 'lodash';
/* util */
import { t } from '@src/locales';
import { getThemeColor } from '@src/util/business/color'

interface StateBGCType {
  [key: string]: string;
}

// @ts-ignore
const storage = useStorage('shb-pc-fe', StorageModuleEnum.TaskManage, getUserId());

// 保存数据到缓存
function saveDataToStorage(key: string, data: StorageSetType) {
  storage.setItem(key, data);
}

// 从缓存获取数据
async function getDataToStorage(key: string, data?: any) {
  return await storage.getItem(key, data);
}

// 状态设置
function formatStatus(status: string) {
  if (!status) return '';
  let res = '';
  switch (status) {
    case 'DRAFT':
      res = t('common.base.draft');
      break;
    case 'NO_START':
      res = t('common.base.notStart');
      break;
    case 'IN_PROGRESS':
      res = t('common.base.processing');
      break;
    case 'COMPLETE':
      res = t('common.base.usualStatus.finish');
      break;
    case 'CANCEL':
      res = t('common.base.usualStatus.canceled');
      break;
    default:
      break;
  }
  return res;
}

// 状态颜色
function stateBGC(state: string) {
  const bgcInfo: StateBGCType = {
    'DRAFT': '#D9D9D9',
    'NO_START': '#FF4D4F',
    'IN_PROGRESS': '#FAAD14',
    'COMPLETE': getThemeColor(),
    'CANCEL': '#D9D9D9',
  }

  let style = { 
    'background-color': bgcInfo[state], 
    color: ''
  };
  if(['DRAFT', 'CANCEL'].includes(state)) style.color = '#595959';

  return style;
}

export {
  saveDataToStorage,
  getDataToStorage,
  formatStatus,
  stateBGC,
}

export { 
  getAdvancedFields, 
  getColumnFields, 
  simplifyTableColumnsProperty
} from '@src/modules/projectManage/projectManageList/util';